<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="lib/vue.global.js"></script>
</head>
<body>
  <div id="root">
    <aa></aa>
    <bb></bb>
  </div>
</body>

<script>
  const { createApp, computed, ref, provide, onMounted, inject } = Vue
  const AA = {
    template: `
      <div>aa: {{ title }}</div>
    `,
    setup () {
      let title = inject('title')
      return {
        title
      }
    }
  }
  const BB = {
    template: `
      <div>bb: </div>
    `
  }
  
  const app = createApp({
    components: {
      aa: AA,
      bb: BB
    },
    setup (props) { // 初始化数据
      const title = ref('hello')

      // 提供数据
      provide('title', title)

      // 声明周期
      onMounted(() => {
        console.log(title)
        setTimeout(() => {
          title.value = 'hi'
        }, 3000)
      })
    }
  })
  app.mount('#root')
</script>
</html>